home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: Utrecht.NL.net!news
- From: E.H.Terwiel@inter.NL.net (E.H. Terwiel (Erik))
- Subject: Re: Question on pointer-to-pointer-to-pointer-...
- X-Nntp-Posting-Host: utr98-17.utrecht.nl.net
- Message-ID: <DLI0p8.H8D@inter.NL.net>
- Sender: news@inter.NL.net (News at newsutr)
- Organization: NLnet
- X-Newsreader: Forte Free Agent 1.0.82
- References: <4dq2ej$m3t@cssun.cs.usm.my>
- Date: Sat, 20 Jan 1996 21:19:21 GMT
-
- bahari@cs.usm.my (Bahari Belaton (Dr)) wrote:
-
- >Hi,
- >Below is one of the question asked by my student about pointer-to-pointer in
- >C - with a specific example on strtod() function. Can anyone help me explain
- >this to my student. Especially on the important of pointer-to-pointer.
-
- >Thanks
-
- >Bahari Belaton
-
- >=======================================================================
- >Dear All,
- > I hope you can enlighthen me a bit.
- >Query 1:
- > According to Deitel, the function prototype for strtod() is:-
- > double strtod(const char *nPtr, char **endPtr) and the function call is
- >as follows :-
- > double d;
- > char *string = "51.2% are admitted";
- > char *stringPtr;
-
- > d = strtod(string, &stringPtr);
-
- >The book says that &stringPtr is assigned the location of the first character
- >after the converted value. How does the function do that?
-
- >I'm still confused with **endPtr. Why the **endPtr(pointer to a
- >pointer) is used?(What is the significance of using a double pointer? Why
- >not just *endPtr since the function assigned the address of first
- >character of the string to &stringPtr. (what about***endPtr?
- >How many pointers to pointer can we used?)
-
- >Thank you very much.
- >Your student,
- >LEE KENG TUNG csi36864@wira2.cs.usm.my
-
- >=================================
-
- Well, after using strtod you will want to know where the function
- stopped converting. If you would pass the char pointer by VALUE (char
- *), the function strtod would remember where it stopped in the pointer
- that was put on the stack when calling the function. At returning,
- strtod would throw away the copy of stringPTR. And you would not know
- where the conversion stopped.
- So you pass stringPTR by REFERENCE: &stringPTR. And have strtod
- remember where it stopped in the real pointer variable.
- Erik
-
-